/**
 * @author Eduardo Leonne Souza de Oliveira
 * @version 1.0
 * Date: 2011-12-29
 * Last change: 2011-12-29 
 * 
 */

package com.leonne.harpacristabrasileira.dao;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;

import com.leonne.harpacristabrasileira.lists.vo.AnthemVO;
import com.leonne.harpacristabrasileira.lists.vo.VerseVO;
import com.leonne.harpacristabrasileira.tools.Utils;

public class VersesDAO extends GenericDAO {

	/**
	 * DAO created specifically to guarantee that the database structure will be
	 * created and populated
	 * 
	 * @param context
	 *            Application base context
	 */
	public VersesDAO(Context context) {
		super(context, "verses");
	}
	
	/**
	 * Get records in the verses table
	 * 
	 * @return ArrayList A list of VerseVO objects
	 */
	public ArrayList<VerseVO> fetchByAnthem(Integer idAnthem) {
		ArrayList<VerseVO> verses = new ArrayList<VerseVO>();
		String sql = "SELECT an.title, ve.verse, ve.ismainverse, an.isfavorite "
				+"FROM verses ve "
				+"LEFT JOIN anthems an ON an.idanthem = ve.idanthem "
				+"WHERE ve.idanthem = " + String.valueOf(idAnthem)
				+" ORDER BY ve.verseOrder";
		Cursor cursor = this.getDatabase().rawQuery(sql, null);
		if (cursor.moveToFirst()) {
			do {
				VerseVO ve = new VerseVO();
				ve.setTitle(cursor.getString(0));
				ve.setVerse(cursor.getString(1));
				ve.setIsMainVerse(cursor.getInt(2));
				ve.setIsFavorite(cursor.getInt(3));
				verses.add(ve);
			} while (cursor.moveToNext());
		}
		return verses;
	}

}
